package pers.qianyu.month_202101.date_20210114;

import java.util.*;

/**
 * 187. 重复的DNA序列
 * https://leetcode-cn.com/problems/repeated-dna-sequences/
 *
 * @author mizzle rain
 * @date 2021-01-14 16:31
 */
public class FindRepeatedDnaSequences {
    public List<String> findRepeatedDnaSequences(String s) {
        int len = s.length();
        if (len < 10) return new ArrayList<>();
        ArrayList<String> res = new ArrayList<>();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i <= len - 10; i++) {
            String sub = s.substring(i, i + 10);
            if (map.containsKey(sub)) {
                if (map.get(sub) == 1) res.add(sub);
                map.put(sub, map.get(sub) + 1);
            } else {
                map.put(sub, 1);
            }
        }
        return res;
    }
}
